package com.kalua.list.domainmodel.security;

import java.util.Arrays;

import com.kalua.list.domainmodel.UUIDIdentifier;

public class UserCredentialsImpl implements UserCredentials {

	private static final long serialVersionUID = -9083997861561916546L;
	
	private UUIDIdentifier id;
	
	private String password;
	private String salt;

	private UserCredentialsImpl() { }
	
	public UserCredentialsImpl(	UUIDIdentifier id, 
												String password, 
												String salt) {
		this();
		setId(id);
		setPassword(password);
		setSalt(salt);
	}
	
	@Override
	public UUIDIdentifier getId() { return this.id; }
	public void setId(UUIDIdentifier id) 
	{ this.id = id; }

	@Override
	public String getPassword() { return this.password; }
	private void setPassword(String password) { this.password = password; }

	@Override
	public String getSalt() { return this.salt; }
	private void setSalt(String salt) { this.salt = salt; }

	public String toString() { return "UserCredentials [id=" + id + "]"; }	
	
	public String toStringFull() {
		return "UserCredentials [id=" + id + "\n\tpassword=" + 
					password + "\n\tsalt=" + salt + "]";
	}
	
	@Override
	public boolean equals(Object candidate) {
		boolean result;
		
		if (this==candidate)
			result = true;
		else if (candidate instanceof UserCredentialsImpl){
			UserCredentialsImpl other = (UserCredentialsImpl) candidate;
			Object[] fields = new Object[]{this.id, this.password, this.salt};
			Object[] otherFields = new Object[]{other.id, other.password, other.salt};
			result = Arrays.equals(fields, otherFields);
		} else result = false;
		
		return result;
	}
}